function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}
function getPayState(str){
var x;
    switch (str)
    {
        case '0':
            x="支付成功";
            break;
        case '1':
            x="支付失败";
            break;
        case '-1':
            x="用户取消，未支付";
            break;
    }
    return x;
}
function toDecimal(x) {
    var f = parseFloat(x);
    if (isNaN(f)) {
        return false;
    }
    var f = x/100;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
        rs = s.length;
        s += '.';
    }
    while (s.length <= rs + 2) {
        s += '0';
    }
    return s;
}
function payinit(){
    var paystate = getPayState(request["state"]);
   // var errorDetail=request["errorDetail"];
    $('#paystate').html(paystate);
   // $('#payContent').html(errorDetail);
    if(request["state"]=='0'){//支付成功
        $('#payResult').html("￥"+toDecimal(request["txamt"]));
        var ordernum= request["orderNum"];
        var txamt=request["txamt"];
        var paramData = {"ordernum":ordernum,"txamt":txamt};
        $.ajax({
            type: "post",
            async: true,//异步，如果等于false 那么就是同步
            url: cochoApp.baseUrl + "/anonymous/phone/getMerchantInfo.do",
            dataType: "json",
            data: paramData,
            success: function (data) {
                if (data != null) {
                    if (data.statusCode == "SUCCESS") {
                        if (data.dataRows.length > 0) {
                            var merchantInfo = data.dataRows[0];
                            $('#shop_name').html(merchantInfo.merchantName);
                            $("#jszc").html(merchantInfo.merchantName);
                            $('#transTime').html(request["transTime"]);
                            $('#orderNum').html(ordernum);
                            $('#paySuccessContent').show();
                            $('#mContent').show();
                        } else {
                            cochoAlert.notificationsWarn("暂无商户信息！");
                        }
                    }
                }
            },
            error: function (data) {
               // alert("请求服务器出错！");
               // return false;
            }
        });

    }

}

var request = new Object();
request = GetRequest();
payinit();